//OpenGL extension routines: allows easy access to,
//e.g., ARB_multitexture or ARB_fragment_program.

//This is a thin wrapper around the "GLEW" (OpenGL
//Extension Wrangler) library available at
//	http://glew.sourceforge.net/

//Orion Sky Lawlor, olawlor@acm.org, 2003/10/30  (Public Domain)
#pragma once

#include "OrionFlames.h"
#include "ogl/util.h"

namespace OrionFlames
{
//Extensions setup.
void oglSetupExt();

//Multitexture support.

//Set up one texture combiner source from these fields.
#define oglTextureCombineOne(n, src_rgb,op_rgb, src_alpha, op_alpha) \
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE##n##_RGB, src_rgb);       \
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND##n##_RGB, op_rgb);       \
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE##n##_ALPHA, src_alpha);   \
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND##n##_ALPHA, op_alpha);   

//Set up texture combiners using these color and alpha modes.
void oglTextureCombine(GLenum Csrc0,GLenum Cop0, GLenum Cmode, GLenum Csrc1,GLenum Cop1,
					   GLenum Asrc0,GLenum Aop0, GLenum Amode, GLenum Asrc1,GLenum Aop1);

//Set up texture combiners to (linearly) blend this texture in by this factor.
void oglTextureCombineLinear(float v);

//Make the current texture "work right", with the usual filtering.
inline void oglTexWorkright()
{
	//Texture state applies to the currently bound texture.
	//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
	//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
}
}